<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        维保合同管理添加
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../../css/main.css" media="all">
    <script type="text/javascript" src="../../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../../lib/layui/css/layui_2.5.7.css">

</head>
<style>

</style>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon"
                                                                        style="line-height:30px">ဂ</i></a>
</div>


<div class="x-body" id="app">
    <form class="layui-form layui-form-pane" id="add">
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <h3><b>基本信息</b></h3> <br>
                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同性质</label>
                    <div class="layui-input-block">
                        <select lay-verify="required" name="natureOfContract">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同标题</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="contractTitle"
                               v-model="repairContract.contractTitle"
                               lay-verify="required" placeholder="合同标题" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>合同编号</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="contractNo"
                               v-model="repairContract.contractNo"
                               placeholder="合同编号" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同类型</label>
                    <div class="layui-input-block">
                        <select lay-verify="required" name="typeOfContract">
                            <option value="">---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>是否带票</label>
                    <div class="layui-input-inline">
                        <select lay-verify="required" name="doYouHaveATicketWithYou">
                            <option selected value="否">否</option>
                            <option value="是">是</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>客户名称</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="maintenanceCustomer"
                               v-model="repairContract.maintenanceCustomer"
                               placeholder="客户名称" class="layui-input">
                    </div>
                </div>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>项目名称</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="entryName"
                               v-model="repairContract.entryName"
                               lay-verify="required" placeholder="项目名称" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>签订日期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="dateOfSigning"
                               v-model="repairContract.dateOfSigning" id="dateOfSigning"
                               lay-verify="required" placeholder="签订日期" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>约定工期</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="schedule"
                               v-model="repairContract.schedule"
                               placeholder="约定工期/个月" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'>*</span>合同金额</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="contractAmount"
                               v-model="repairContract.contractAmount"
                               lay-verify="required" placeholder="合同金额" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>金额大写</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="amountInWords"
                               v-model="repairContract.amountInWords" readonly
                               placeholder="金额大写" style="background-color:  #e6e6e6" class="layui-input">
                    </div>
                </div>


                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>涉及电梯</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="involvingElevators"
                               v-model="repairContract.involvingElevators"
                               placeholder="涉及电梯" class="layui-input">
                    </div>
                </div>

                <h3><b>甲方负责人</b></h3> <br>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>姓名</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyAName"
                               v-model="repairContract.personInChargeOfPartyAName"
                               placeholder="姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>职位</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyAPosition"
                               v-model="repairContract.personInChargeOfPartyAPosition"
                               placeholder="职位" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>联系方式</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyAPhone"
                               v-model="repairContract.personInChargeOfPartyAPhone"
                               placeholder="联系方式" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>备注</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyARemark"
                               v-model="repairContract.personInChargeOfPartyARemark"
                               placeholder="备注" class="layui-input">
                    </div>
                </div>
                <h3><b>乙方负责人</b></h3> <br>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>姓名</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyBName"
                               v-model="repairContract.personInChargeOfPartyBName"
                               placeholder="姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>职位</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyBPosition"
                               v-model="repairContract.personInChargeOfPartyBPosition"
                               placeholder="职位" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>联系方式</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyBPhone"
                               v-model="repairContract.personInChargeOfPartyBPhone"
                               placeholder="联系方式" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>备注</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="personInChargeOfPartyBRemark"
                               v-model="repairContract.personInChargeOfPartyBRemark"
                               placeholder="备注" class="layui-input">
                    </div>
                </div>
                <h3><b>成本/利润估算</b></h3> <br>

                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>成本</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="text" name="costProfitEstimation"
                               v-model="repairContract.costProfitEstimation"
                               placeholder="请输入费用，如人工费、材料费或者其他费用" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>利润估算</label>
                    <div class="layui-input-inline">
                        <input  autocomplete="off"  type="number" name="costProfitEstimationAmount"
                               v-model="repairContract.costProfitEstimationAmount"
                               placeholder="请输入费用金额" class="layui-input">
                    </div>
                </div>

                <div class=" layui-form-item">
                    <label class="layui-form-label"> <span class='x-red'></span>备注</label>
                    <div class="layui-input-block">
                        <textarea name="remark" placeholder="请输入内容" v-model="repairContract.remark"
                                  class="layui-textarea"></textarea>
                    </div>
                </div>


                <div style="text-align: center" class="layui-form-item">
                    <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                        保存
                    </button>
                </div>
                <div style="height:100px;"></div>
            </div>

        </div>

    </form>
</div>
<script type="text/javascript" src="../../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../../js/myAjax.js"></script>
<script type="text/javascript" src="../../../js/pub.js"></script>
<script src="../../../lib/layui/layui2.5.7.js" charset="utf-8"></script>
<script src="../../../js/x-layui.js" charset="utf-8"></script>
<script src="../../../js/vue.min.js" charset="utf-8"></script>

<script>
    layui.use(['element', 'layer', 'form', 'laydate'], function () {
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        laydate = layui.laydate;//日期插件
        form = layui.form;
        okLoading.close($);
    })

</script>
<script>

    var recordId = getQueryVariable("recordId");


    layui.use(['laydate', 'form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            var laydate = layui.laydate;

            laydate.render({
                elem: '#dateOfSigning', //指定元素
                trigger: 'click',
                type: 'date',
                done: function (value, date, endDate) {
                    vm.repairContract.dateOfSigning = value
                }
            });


            //监听审批提交
            form.on('submit(sub)',
                function (data) {
                    let form = data.field;
                    form.userId = $userId;
                    form.id = vm.repairContract.id;
                    form.type = '修理合同';
                    vm.repairContract.id == null ? form.operationType = 'add' : form.operationType = 'edit';

                    let request = {
                        url: 'repairContract/addRepairContract',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();
                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });
        });


    const vm = new Vue({
        el: "#app",
        data: {
            repairContract: {
                id: null,
                natureOfContract: null,
                contractTitle: null,
                typeOfContract: null,
                doYouHaveATicketWithYou: null,
                maintenanceCustomer: null,
                entryName: null,
                dateOfSigning: null,
                schedule: null,
                contractAmount: null,
                amountInWords: null,
                involvingElevators: null,
                personInChargeOfPartyAName: null,
                personInChargeOfPartyAPosition: null,
                personInChargeOfPartyAPhone: null,
                personInChargeOfPartyARemark: null,
                personInChargeOfPartyBName: null,
                personInChargeOfPartyBPosition: null,
                personInChargeOfPartyBPhone: null,
                personInChargeOfPartyBRemark: null,
                costProfitEstimation: null,
                costProfitEstimationAmount: null,
                remark: null,
                type: null,
            }
        },
        created() {
            if (recordId) {
                let request = {
                    url: 'repairContract/findRepairContract',
                    data: {
                        userId: $userId,
                        recordId: recordId
                    },
                    method: "POST"
                };
                sendRequest(request, (res) => {
                    // console.log(res);
                    this.repairContract = res.data;
                })

            }
        },
    });
    setTimeout(() => {
        //修改状态
        let form = layui.form;


        //合同性质
        let request = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'NATURE_OF_CONTRACT'
            },
            method: "POST",
        };
        sendRequest(request, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=natureOfContract]").append(opt);
            });

            $("select[name=natureOfContract]").val(vm.repairContract.natureOfContract);

            form.render('select');

        });
        //合同类型
        let request1 = {
            url: 'dictionary/findDataDictionaryValue',
            data: {
                userId: $userId,
                label: 'TYPE_OF_CONTRACT'
            },
            method: "POST",
        };
        sendRequest(request1, (res) => {
            let x = res.data;
            $.each(x, function (index, item) {
                let opt = $("<option value=" + item + ">" + item + "</option>");
                $("select[name=typeOfContract]").append(opt);
            });

            $("select[name=typeOfContract]").val(vm.repairContract.typeOfContract);

            form.render('select');

        });

        $("select[name=doYouHaveATicketWithYou]").val(vm.repairContract.doYouHaveATicketWithYou);

        form.render('select');


    }, 500)
</script>

<script>
    var AIW_number = {0: '零', 1: '壹', 2: '贰', 3: '叁', 4: '肆', 5: '伍', 6: '陆', 7: '柒', 8: '捌', 9: '玖'}
    var AIW_unitN = ['兆', '亿', '万', '个'];
    var AIW_unitP = ['厘', '分', '角'];
    var AIW_unitU = ['仟', '佰', '拾', '个'];


    function amountInWordsRound(round) {
        if (!round) return '';
        var words = '';
        var rounds = Array.from(round);
        var length = rounds.length;
        var unitU = JSON.parse(JSON.stringify(AIW_unitU));
        var unitN = JSON.parse(JSON.stringify(AIW_unitN));
        while (length > 0) {
            length--;
            A = rounds.pop();
            U = unitU.pop();
            N = (unitU.length == 3 ? unitN.pop() : '');
            if (A != 0) words = AIW_number[A] + U + N + words;
            else words = AIW_number[A] + N + words;
            if (unitU.length == 0) unitU = JSON.parse(JSON.stringify(AIW_unitU));
            words = words.replace('undefined', '');
            words = words.replace('个', '');
        }
        return amountInWordsFormate(words)
    }

    function amountInWordsF(fix) {
        if (!fix) return '';
        var unitP = JSON.parse(JSON.stringify(AIW_unitP));
        var fixs = Array.from(fix);
        var words = '';
        $.each(fixs, function (i, o) {
            var P = unitP.pop();
            if (o == 0) words += AIW_number[o];
            else words += AIW_number[o] + P;
            words = words.replace('undefined', '')
        })
        return amountInWordsFormate(words)
    }

    function amountInWordsFormate(words) {
        //去除中位零
        length = words.length;
        while (length > 1) {
            length--;
            var now = words.charAt(length);
            var before = words.charAt(length - 1);
            var after = words.charAt(length + 1);
            if (now == before || (AIW_unitN.includes(after) && now == AIW_number[0])) {
                words = words.substring(0, length) + words.substring(length + 1);
                length = words.length
            }
        }
        //去除末位零
        length = 2;
        while (length > 1) {
            length--;
            if (words.charAt(words.length - 1) == AIW_number[0] && words.length > 1) {
                words = words.substring(0, words.length - 1);
                length = 2
            }
        }
        return words
    }

    function amountInWords(amount) {
        var AIW = (amount + '').split('.');
        if (AIW.length > 1)
            return amountInWordsRound(AIW[0]) + '元' + amountInWordsF(AIW[1]);
        else
            return amountInWordsRound(AIW[0]) + '元整'
    }


    var ca = $("input[name=contractAmount]");
    ca.change(function () {
        var val = amountInWords(ca.val() == '' ? 0 : ca.val());
        $("input[name=amountInWords]").val(val);
        vm.repairContract.amountInWords = val;
    })


</script>

</body>

</html>
